//
//  ViewController.m
//  4.7
//
//  Created by 王奎卿 on 2017/4/7.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "ViewController.h"
#import "MainView.h"
#import "MainCell.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    MainView *_view;
    UIView *_view2;
}
@property (nonatomic,strong)UITableView *mainViewCell;
@property (nonatomic,assign)BOOL isb;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self showView];
}

- (void)showView
{
    _view = [[MainView alloc]initWithFrame:_view2.frame];
    _view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 64, 150, 150)];

    _view2 = _view;
    _view2.backgroundColor = [UIColor redColor];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(click:)];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"➕" forState:0];
    btn.frame = CGRectMake(0, 0, 33, 33);
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightItem;
    [self.view addSubview:self.mainViewCell];
    [self.view addSubview:_view2];
    _view2.hidden = YES;
//    [self.view sendSubviewToBack:_view2];
}

- (void)click:(UIButton *)sender
{
//    self.isb = sender.selected;
    
//    if (self.isb == YES)
//    {
////        [self.view addSubview:_view2];
//        _view2.hidden = NO;
//        self.isb = NO;
//    }
//    else if (self.isb == NO)
//    {
////        [_view2 removeFromSuperview];
//        _view2.hidden = YES;
//        self.isb = YES;
//    }
    
    if (sender.isSelected == NO)
    {
        sender.selected = YES;
        _view2.hidden = NO;
    }
    else if (sender.isSelected == YES)
    {
        sender.selected = NO;
        _view2.hidden = YES;
    }
}

- (UITableView *)mainViewCell
{
    if (!_mainViewCell)
    {
        CGSize size = [UIScreen mainScreen].bounds.size;
        _mainViewCell = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height) style:UITableViewStyleGrouped];
        
        _mainViewCell.delegate = self;
        
        _mainViewCell.dataSource = self;
    }
    return _mainViewCell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"111"];
        
        if (!cell)
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"111"];
        }
        cell.textLabel.text = @"联想集团北京分公司上地公司";
        cell.detailTextLabel.text = @"IT电商";
        return cell;
    }
    else if (indexPath.section == 1)
    {
        MainCell *cell = [tableView dequeueReusableCellWithIdentifier:@"222"];
        
        if (!cell)
        {
            cell = [[MainCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"222"];
        }
        return cell;
    }
    return nil;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
